import storejs from 'storejs'
const state = {
  forms:{}
}

// getters
const getters = {
    getForm: (state) => (key) => {
      return state.forms[key];
    }
}

// actions
const actions = {
    keepForm({ state, commit }, payload) {
      commit('setForm', payload);
    },
    clearForm({ state, commit }, key){
      commit('delForm', key);
    }
}

// mutations
const mutations = {
    setForm(state, {key, formModule}) {
      for(let k in state.forms){
        if(k !== key) delete state.forms[k];
      }
      state.forms[key] = formModule;
    },
    delForm(state, key){
      delete state.forms[key]
    }
}

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
}
